home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / sound / misc / mpeg1_iis.lha / mpeg1_iis / musicout.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-11  |  23.2 KB  |  557 lines

  1. /**********************************************************************
  2. Copyright (c) 1991 MPEG/audio software simulation group, All Rights Reserved
  3. musicout.c
  4. **********************************************************************/
  5. /**********************************************************************
  6.  * MPEG/audio coding/decoding software, work in progress              *
  7.  *   NOT for public distribution until verified and approved by the   *
  8.  *   MPEG/audio committee.  For further information, please contact   *
  9.  *   Davis Pan, 508-493-2241, e-mail: pan@3d.enet.dec.com             *
  10.  *                                                                    *
  11.  * VERSION 4.1                                                        *
  12.  *   changes made since last update:                                  *
  13.  *   date   programmers                comment                        *
  14.  * 2/25/91  Douglas Wong        start of version 1.0 records          *
  15.  * 3/06/91  Douglas Wong        rename setup.h to dedef.h             *
  16.  *                              removed extraneous variables          *
  17.  *                              removed window_samples (now part of   *
  18.  *                              filter_samples)                       *
  19.  * 3/07/91  Davis Pan           changed output file to "codmusic"     *
  20.  * 5/10/91  Vish (PRISM)        Ported to Macintosh and Unix.         *
  21.  *                              Incorporated new "out_fifo()" which   *
  22.  *                              writes out last incomplete buffer.    *
  23.  *                              Incorporated all AIFF routines which  *
  24.  *                              are also compatible with SUN.         *
  25.  *                              Incorporated user interface for       *
  26.  *                              specifying sound file names.          *
  27.  *                              Also incorporated user interface for  *
  28.  *                              writing AIFF compatible sound files.  *
  29.  * 27jun91  dpwe (Aware)        Added musicout and &sample_frames as  *
  30.  *                              args to out_fifo (were glob refs).    *
  31.  *                              Used new 'frame_params' struct.       *
  32.  *                              Clean,simplify, track clipped output  *
  33.  *                              and total bits/frame received.        *
  34.  * 7/10/91  Earle Jennings      changed to floats to FLOAT            *
  35.  *10/ 1/91  S.I. Sudharsanan,   Ported to IBM AIX platform.           *
  36.  *          Don H. Lee,                                               *
  37.  *          Peter W. Farrett                                          *
  38.  *10/ 3/91  Don H. Lee          implemented CRC-16 error protection   *
  39.  *                              newly introduced functions are        *
  40.  *                              buffer_CRC and recover_CRC_error      *
  41.  *                              Additions and revisions are marked    *
  42.  *                              with "dhl" for clarity                *
  43.  * 2/11/92  W. Joseph Carter    Ported new code to Macintosh.  Most   *
  44.  *                              important fixes involved changing     *
  45.  *                              16-bit ints to long or unsigned in    *
  46.  *                              bit alloc routines for quant of 65535 *
  47.  *                              and passing proper function args.     *
  48.  *                              Removed "Other Joint Stereo" option   *
  49.  *                              and made bitrate be total channel     *
  50.  *                              bitrate, irrespective of the mode.    *
  51.  *                              Fixed many small bugs & reorganized.  *
  52.  *19 aug 92 Soren H. Nielsen    Changed MS-DOS file name extensions.  *
  53.  * 8/27/93 Seymour Shlien,      Fixes in Unix and MSDOS ports,        *
  54.  *         Daniel Lauzon, and                                         *
  55.  *         Bill Truerniet                                             *
  56.  *--------------------------------------------------------------------*
  57.  * 4/23/92  J. Pineda           Added code for layer III.  LayerIII   *
  58.  *          Amit Gulati         decoding is currently performed in    *
  59.  *                              two-passes for ease of sideinfo and   *
  60.  *                              maindata buffering and decoding.      *
  61.  *                              The second (computation) pass is      *
  62.  *                              activated with "decode -3 <outfile>"  *
  63.  * 10/25/92 Amit Gulati         Modified usage() for layerIII         *
  64.  * 12/10/92 Amit Gulati         Changed processing order of re-order- *
  65.  *                              -ing step.  Fixed adjustment of       *
  66.  *                              main_data_end pointer to exclude      *
  67.  *                              side information.                     *
  68.  *  9/07/93 Toshiyuki Ishino    Integrated Layer III with Ver 3.9.    *
  69.  *--------------------------------------------------------------------*
  70.  * 11/20/93 Masahiro Iwadare    Integrated Layer III with Ver 4.0.    *
  71.  *--------------------------------------------------------------------*
  72.  *  7/14/94 Juergen Koller      Bug fixes in Layer III code           *
  73.  **********************************************************************/
  74.  
  75. #include        "common.h"
  76. #include        "decoder.h"
  77.  
  78. /********************************************************************
  79. /*
  80. /*        This part contains the MPEG I decoder for Layers I & II.
  81. /*
  82. /*********************************************************************/
  83.  
  84. /****************************************************************
  85. /*
  86. /*        For MS-DOS user (Turbo c) change all instance of malloc
  87. /*        to _farmalloc and free to _farfree. Compiler model hugh
  88. /*        Also make sure all the pointer specified are changed to far.
  89. /*
  90. /*****************************************************************/
  91.  
  92. /*********************************************************************
  93. /*
  94. /* Core of the Layer II decoder.  Default layer is Layer II.
  95. /*
  96. /*********************************************************************/
  97.  
  98. /* Global variable definitions for "musicout.c" */
  99.  
  100. char *programName;
  101. int main_data_slots();
  102. int side_info_slots();
  103.  
  104. /* Implementations */
  105.  
  106. main(argc, argv)
  107. int argc;
  108. char **argv;
  109. {
  110. /*typedef short PCM[2][3][SBLIMIT];*/
  111. typedef short PCM[2][SSLIMIT][SBLIMIT];
  112.     PCM FAR *pcm_sample;
  113. typedef unsigned int SAM[2][3][SBLIMIT];
  114.     SAM FAR *sample;
  115. typedef double FRA[2][3][SBLIMIT];
  116.     FRA FAR *fraction;
  117. typedef double VE[2][HAN_SIZE];
  118.     VE FAR *w;
  119.  
  120.     Bit_stream_struc  bs;
  121.     frame_params      fr_ps;
  122.     layer             info;
  123.     FILE              *musicout;
  124.     unsigned long     sample_frames;
  125.  
  126.     int               i, j, k, stereo, done=FALSE, clip, sync;
  127.     int               error_protection, crc_error_count, total_error_count;
  128.     unsigned int      old_crc, new_crc;
  129.     unsigned int      bit_alloc[2][SBLIMIT], scfsi[2][SBLIMIT],
  130.                       scale_index[2][3][SBLIMIT];
  131.     unsigned long     bitsPerSlot, samplesPerFrame, frameNum = 0;
  132.     unsigned long     frameBits, gotBits = 0;
  133.     IFF_AIFF          pcm_aiff_data;
  134.     char              encoded_file_name[MAX_NAME_SIZE];
  135.     char              decoded_file_name[MAX_NAME_SIZE];
  136.     char              t[50];
  137.     int               need_aiff;
  138.     int               need_esps;        /* MI */
  139.     int topSb = 0;
  140.  
  141. III_scalefac_t III_scalefac;
  142. III_side_info_t III_side_info;
  143.  
  144. #ifdef  MACINTOSH
  145.     console_options.nrows = MAC_WINDOW_SIZE;
  146.     argc = ccommand(&argv);
  147. #endif
  148.  
  149.     /* Most large variables are declared dynamically to ensure
  150.        compatibility with smaller machines */
  151.  
  152.     pcm_sample = (PCM FAR *) mem_alloc((long) sizeof(PCM), "PCM Samp");
  153.     sample = (SAM FAR *) mem_alloc((long) sizeof(SAM), "Sample");
  154.     fraction = (FRA FAR *) mem_alloc((long) sizeof(FRA), "fraction");
  155.     w = (VE FAR *) mem_alloc((long) sizeof(VE), "w");
  156.  
  157.     fr_ps.header = &info;
  158.     fr_ps.tab_num = -1;                /* no table loaded */
  159.     fr_ps.alloc = NULL;
  160.     for (i=0;i<HAN_SIZE;i++) for (j=0;j<2;j++) (*w)[j][i] = 0.0;
  161.  
  162.     programName = argv[0];
  163.     if(argc==1) {        /* no command line args -> interact */
  164.        do {
  165.           printf ("Enter encoded file name <required>: ");
  166.           gets (encoded_file_name);
  167.           if (encoded_file_name[0] == NULL_CHAR)
  168.              printf ("Encoded file name is required. \n");
  169.        } while (encoded_file_name[0] == NULL_CHAR);
  170.        printf (">>> Encoded file name is: %s \n", encoded_file_name);
  171. #ifdef  MS_DOS
  172.        printf ("Enter MPEG decoded file name <%s>: ",
  173.                new_ext(encoded_file_name, DFLT_OPEXT)); /* 92-08-19 shn */
  174. #else
  175.        printf ("Enter MPEG decoded file name <%s%s>: ", encoded_file_name,
  176.                DFLT_OPEXT);
  177. #endif
  178.        gets (decoded_file_name);
  179.        if (decoded_file_name[0] == NULL_CHAR) {
  180. #ifdef  MS_DOS
  181.            /* replace old extension with new one, 92-08-19 shn */
  182.            strcpy(decoded_file_name,new_ext(encoded_file_name, DFLT_OPEXT));
  183. #else
  184.            strcat (strcpy(decoded_file_name, encoded_file_name), DFLT_OPEXT);
  185. #endif
  186.        }
  187.        printf (">>> MPEG decoded file name is: %s \n", decoded_file_name);
  188.  
  189.        printf(
  190.           "Do you wish to write an AIFF compatible sound file ? (y/<n>) : ");
  191.        gets(t);
  192.        if (*t == 'y' || *t == 'Y') need_aiff = TRUE;
  193.        else                        need_aiff = FALSE;
  194.        if (need_aiff)
  195.             printf(">>> An AIFF compatible sound file will be written\n");
  196.        else printf(">>> A non-headered PCM sound file will be written\n");
  197.  
  198.        printf(
  199.           "Do you wish to exit (last chance before decoding) ? (y/<n>) : ");
  200.        gets(t);
  201.        if (*t == 'y' || *t == 'Y') exit(0);
  202.     }
  203.     else {        /* interpret CL Args */
  204.        int i=0, err=0;
  205.  
  206.        need_aiff = FALSE;
  207.        need_esps = FALSE;    /* MI */
  208.        encoded_file_name[0] = '\0';
  209.        decoded_file_name[0] = '\0';
  210.  
  211.        while(++i<argc && err == 0) {
  212.           char c, *token, *arg, *nextArg;
  213.           int  argUsed;
  214.  
  215.           token = argv[i];
  216.           if(*token++ == '-') {
  217.              if(i+1 < argc) nextArg = argv[i+1];
  218.              else           nextArg = "";
  219.              argUsed = 0;
  220.              while(c = *token++) {
  221.                 if(*token /* NumericQ(token) */) arg = token;
  222.                 else                             arg = nextArg;
  223.                 switch(c) {
  224.                    case 's':  topSb = atoi(arg); argUsed = 1;
  225.                       if(topSb<1 || topSb>SBLIMIT) {
  226.                          fprintf(stderr, "%s: -s band %s not %d..%d\n",
  227.                                  programName, arg, 1, SBLIMIT);
  228.                          err = 1;
  229.                       }
  230.                       break;
  231.                    case 'A':  need_aiff = TRUE; break;
  232.                    case 'E':  need_esps = TRUE; break;    /* MI */
  233.                    default:   fprintf(stderr,"%s: unrecognized option %c\n",
  234.                                       programName, c);
  235.                       err = 1; break;
  236.                 }
  237.                 if(argUsed) {
  238.                    if(arg == token) token = ""; /* no more from token */
  239.                    else             ++i; /* skip arg we used */
  240.                    arg = ""; argUsed = 0;
  241.                 }
  242.              }
  243.           }
  244.           else {
  245.              if(encoded_file_name[0] == '\0')
  246.                 strcpy(encoded_file_name, argv[i]);
  247.              else
  248.                 if(decoded_file_name[0] == '\0')
  249.                    strcpy(decoded_file_name, argv[i]);
  250.                 else {
  251.                    fprintf(stderr,
  252.                            "%s: excess arg %s\n", programName, argv[i]);
  253.                    err = 1;
  254.                 }
  255.           }
  256.        }
  257.  
  258.        if(err || encoded_file_name[0] == '\0') usage();  /* never returns */
  259.  
  260.        if(decoded_file_name[0] == '\0') {
  261.           strcpy(decoded_file_name, encoded_file_name);
  262.           strcat(decoded_file_name, DFLT_OPEXT);
  263.        }
  264.  
  265.     }
  266.     /* report results of dialog / command line */
  267.     printf("Input file = '%s'  output file = '%s'\n",
  268.            encoded_file_name, decoded_file_name);
  269.     if(need_aiff) printf("Output file written in AIFF format\n");
  270.     if(need_esps) printf("Output file written in ESPS format\n"); /* MI */
  271.  
  272.     if ((musicout = fopen(decoded_file_name, "w+b")) == NULL) {
  273.        printf ("Could not create \"%s\".\n", decoded_file_name);
  274.        exit(1);
  275.     }
  276.  
  277.     open_bit_stream_r(&bs, encoded_file_name, BUFFER_SIZE);
  278.  
  279.     if (need_aiff)
  280.        if (aiff_seek_to_sound_data(musicout) == -1) {
  281.           printf("Could not seek to PCM sound data in \"%s\".\n",
  282.                  decoded_file_name);
  283.           exit(1);
  284.        }
  285.  
  286.     sample_frames = 0;
  287.  
  288.     while (!end_bs(&bs)) {
  289.  
  290.        sync = seek_sync(&bs, SYNC_WORD, SYNC_WORD_LNGTH);
  291.        frameBits = sstell(&bs) - gotBits;
  292.        if(frameNum > 0)        /* don't want to print on 1st loop; no lay */
  293.           if(frameBits%bitsPerSlot)
  294.              fprintf(stderr,"Got %ld bits = %ld slots plus %ld\n",
  295.                      frameBits, frameBits/bitsPerSlot, frameBits%bitsPerSlot);
  296.        gotBits += frameBits;
  297.  
  298.        if (!sync) {
  299.           printf("Frame cannot be located\n");
  300.           printf("Input stream may be empty\n");
  301.           done = TRUE;
  302.           /* finally write out the buffer */
  303.           if (info.lay != 1) out_fifo(*pcm_sample, 3, &fr_ps, done,
  304.                                       musicout, &sample_frames);
  305.           else               out_fifo(*pcm_sample, 1, &fr_ps, done,
  306.                                       musicout, &sample_frames);
  307.           break;
  308.        }
  309.  
  310.        decode_info(&bs, &fr_ps);
  311.        hdr_to_frps(&fr_ps);
  312.        stereo = fr_ps.stereo;
  313.        error_protection = info.error_protection;
  314.        crc_error_count = 0;
  315.        total_error_count = 0;
  316.        if(frameNum == 0) WriteHdr(&fr_ps, stdout);  /* printout layer/mode */
  317.  
  318. #ifdef ESPS
  319. if (frameNum == 0 && need_esps) {
  320. esps_write_header(musicout,(long) sample_frames, (double)
  321. s_freq[info.sampling_frequency] * 1000,
  322. (int) stereo, decoded_file_name );
  323. } /* MI */
  324. #endif
  325.  
  326.        fprintf(stderr, "{%4lu}", frameNum++); fflush(stderr);
  327.        if (error_protection) buffer_CRC(&bs, &old_crc);
  328.  
  329.        switch (info.lay) {
  330.  
  331.           case 1: {
  332.              bitsPerSlot = 32;        samplesPerFrame = 384;
  333.              I_decode_bitalloc(&bs,bit_alloc,&fr_ps);
  334.              I_decode_scale(&bs, bit_alloc, scale_index, &fr_ps);
  335.  
  336.              if (error_protection) {
  337.                 I_CRC_calc(&fr_ps, bit_alloc, &new_crc);
  338.                 if (new_crc != old_crc) {
  339.                    crc_error_count++;
  340.                    total_error_count++;
  341.                    recover_CRC_error(*pcm_sample, crc_error_count,
  342.                                      &fr_ps, musicout, &sample_frames);
  343.                    break;
  344.                 }
  345.                 else crc_error_count = 0;
  346.              }
  347.  
  348.              clip = 0;
  349.              for (i=0;i<SCALE_BLOCK;i++) {
  350.                 I_buffer_sample(&bs,(*sample),bit_alloc,&fr_ps);
  351.                 I_dequantize_sample(*sample,*fraction,bit_alloc,&fr_ps);
  352.                 I_denormalize_sample((*fraction),scale_index,&fr_ps);
  353.                 if(topSb>0)        /* clear channels to 0 */
  354.                    for(j=topSb; j<fr_ps.sblimit; ++j)
  355.                       for(k=0; k<stereo; ++k)
  356.                          (*fraction)[k][0][j] = 0;
  357.  
  358.                 for (j=0;j<stereo;j++) {
  359.                    clip += SubBandSynthesis (&((*fraction)[j][0][0]), j,
  360.                                              &((*pcm_sample)[j][0][0]));
  361.                 }
  362.                 out_fifo(*pcm_sample, 1, &fr_ps, done,
  363.                          musicout, &sample_frames);
  364.              }
  365.              if(clip > 0) printf("%d output samples clipped\n", clip);
  366.              break;
  367.           }
  368.  
  369.           case 2: {
  370.              bitsPerSlot = 8;        samplesPerFrame = 1152;
  371.              II_decode_bitalloc(&bs, bit_alloc, &fr_ps);
  372.              II_decode_scale(&bs, scfsi, bit_alloc, scale_index, &fr_ps);
  373.  
  374.              if (error_protection) { 
  375.                 II_CRC_calc(&fr_ps, bit_alloc, scfsi, &new_crc);
  376.                 if (new_crc != old_crc) {
  377.                    crc_error_count++;
  378.                    total_error_count++;
  379.                    recover_CRC_error(*pcm_sample, crc_error_count,
  380.                                      &fr_ps, musicout, &sample_frames);
  381.                    break;
  382.                 }
  383.                 else crc_error_count = 0;
  384.              }
  385.  
  386.              clip = 0;
  387.              for (i=0;i<SCALE_BLOCK;i++) {
  388.                 II_buffer_sample(&bs,(*sample),bit_alloc,&fr_ps);
  389.                 II_dequantize_sample((*sample),bit_alloc,(*fraction),&fr_ps);
  390.                 II_denormalize_sample((*fraction),scale_index,&fr_ps,i>>2);
  391.  
  392.                 if(topSb>0)        /* debug : clear channels to 0 */
  393.                    for(j=topSb; j<fr_ps.sblimit; ++j)
  394.                       for(k=0; k<stereo; ++k)
  395.                          (*fraction)[k][0][j] =
  396.                          (*fraction)[k][1][j] =
  397.                          (*fraction)[k][2][j] = 0;
  398.  
  399.                 for (j=0;j<3;j++) for (k=0;k<stereo;k++) {
  400.                    clip += SubBandSynthesis (&((*fraction)[k][j][0]), k,
  401.                                              &((*pcm_sample)[k][j][0]));
  402.                 }
  403.                 out_fifo(*pcm_sample, 3, &fr_ps, done, musicout,
  404.                          &sample_frames);
  405.              }
  406.              if(clip > 0) printf("%d samples clipped\n", clip);
  407.              break;
  408.           }
  409.  
  410.           case 3: {
  411.              int nSlots;
  412.              int gr, ch, ss, sb, main_data_end, flush_main ;
  413.          int  bytes_to_discard ;
  414.          static int frame_start = 0;
  415.              bitsPerSlot = 8;        samplesPerFrame = 1152;
  416.  
  417.              III_get_side_info(&bs, &III_side_info, &fr_ps);
  418.              nSlots = main_data_slots(fr_ps);
  419.              for (; nSlots > 0; nSlots--)  /* read main data. */
  420.                 hputbuf((unsigned int) getbits(&bs,8), 8);
  421.          main_data_end = hsstell() / 8; /*of privious frame*/
  422.              if ( flush_main=(hsstell() % bitsPerSlot) ) { 
  423.                 hgetbits((int)(bitsPerSlot - flush_main));
  424.         main_data_end ++;
  425.          }
  426.              bytes_to_discard = frame_start - main_data_end
  427.                          - III_side_info.main_data_begin ;
  428.              if( main_data_end > 4096 )
  429.              {   frame_start -= 4096;
  430.                  rewindNbytes( 4096 );
  431.              }
  432.  
  433.              frame_start += main_data_slots(fr_ps);
  434.              if (bytes_to_discard < 0) {
  435.          printf("Not enough main data to decode frame %d.  Frame discarded.\n", 
  436.                         frameNum - 1); break;
  437.              }
  438.              for (; bytes_to_discard > 0; bytes_to_discard--) hgetbits(8);
  439.  
  440.              clip = 0;
  441.              for (gr=0;gr<2;gr++) {
  442.                double lr[2][SBLIMIT][SSLIMIT],ro[2][SBLIMIT][SSLIMIT];
  443.  
  444.                for (ch=0; ch<stereo; ch++) {
  445.                  long int is[SBLIMIT][SSLIMIT];   /* Quantized samples. */
  446.                  int part2_start;
  447.                  part2_start = hsstell();
  448.                  III_get_scale_factors(III_scalefac,&III_side_info,gr,ch,
  449.             &fr_ps);
  450.                  III_hufman_decode(is, &III_side_info, ch, gr, part2_start,
  451.                                    &fr_ps);
  452.                  III_dequantize_sample(is, ro[ch], III_scalefac,
  453.                                    &(III_side_info.ch[ch].gr[gr]), ch, &fr_ps);
  454.                }
  455.                III_stereo(ro,lr,III_scalefac,
  456.                             &(III_side_info.ch[0].gr[gr]), &fr_ps);
  457.                for (ch=0; ch<stereo; ch++) {
  458.                     double re[SBLIMIT][SSLIMIT];
  459.                     double hybridIn[SBLIMIT][SSLIMIT];/* Hybrid filter input */
  460.                     double hybridOut[SBLIMIT][SSLIMIT];/* Hybrid filter out */
  461.                     double polyPhaseIn[SBLIMIT];     /* PolyPhase Input. */
  462.  
  463.                     III_reorder (lr[ch],re,&(III_side_info.ch[ch].gr[gr]),
  464.                                   &fr_ps);
  465.                     III_antialias(re, hybridIn, /* Antialias butterflies. */
  466.                                   &(III_side_info.ch[ch].gr[gr]), &fr_ps);
  467.                     for (sb=0; sb<SBLIMIT; sb++) { /* Hybrid synthesis. */
  468.                         III_hybrid(hybridIn[sb], hybridOut[sb], sb, ch,
  469.                                    &(III_side_info.ch[ch].gr[gr]), &fr_ps);
  470.                     }
  471.                     for (ss=0;ss<18;ss++) /*Frequency inversion for polyphase.*/
  472.                        for (sb=0; sb<SBLIMIT; sb++)
  473.                           if ((ss%2) && (sb%2))
  474.                              hybridOut[sb][ss] = -hybridOut[sb][ss];
  475.                     for (ss=0;ss<18;ss++) { /* Polyphase synthesis */
  476.                         for (sb=0; sb<SBLIMIT; sb++)
  477.                             polyPhaseIn[sb] = hybridOut[sb][ss];
  478.                         clip += SubBandSynthesis (polyPhaseIn, ch,
  479.                                                   &((*pcm_sample)[ch][ss][0]));
  480.                         }
  481.                     }
  482.                 /* Output PCM sample points for one granule. */
  483.                 out_fifo(*pcm_sample, 18, &fr_ps, done, musicout,
  484.                          &sample_frames);
  485.              }
  486.              if(clip > 0) printf("%d samples clipped.\n", clip);
  487.              break;
  488.           }
  489.        }
  490.     }
  491.  
  492.     if (need_aiff) {
  493.        pcm_aiff_data.numChannels       = stereo;
  494.        pcm_aiff_data.numSampleFrames   = sample_frames;
  495.        pcm_aiff_data.sampleSize        = 16;
  496.        pcm_aiff_data.sampleRate        = s_freq[info.sampling_frequency]*1000;
  497. #ifdef IFF_LONG
  498.        pcm_aiff_data.sampleType        = IFF_ID_SSND;
  499. #else
  500.        strncpy(&pcm_aiff_data.sampleType,IFF_ID_SSND,4);
  501. #endif
  502.        pcm_aiff_data.blkAlgn.offset    = 0;
  503.        pcm_aiff_data.blkAlgn.blockSize = 0;
  504.  
  505.        if (aiff_write_headers(musicout, &pcm_aiff_data) == -1) {
  506.           printf("Could not write AIFF headers to \"%s\"\n",
  507.                  decoded_file_name);
  508.           exit(2);
  509.        }
  510.     }
  511.  
  512.     printf("Avg slots/frame = %.3f; b/smp = %.2f; br = %.3f kbps\n",
  513.            (FLOAT) gotBits / (frameNum * bitsPerSlot),
  514.            (FLOAT) gotBits / (frameNum * samplesPerFrame),
  515.            (FLOAT) gotBits / (frameNum * samplesPerFrame) *
  516.            s_freq[info.sampling_frequency]);
  517.  
  518.     close_bit_stream_r(&bs);
  519.     fclose(musicout);
  520.  
  521.     /* for the correct AIFF header information */
  522.     /*             on the Macintosh            */
  523.     /* the file type and the file creator for  */
  524.     /* Macintosh compatible Digidesign is set  */
  525.  
  526. #ifdef  MACINTOSH
  527.     if (need_aiff) set_mac_file_attr(decoded_file_name, VOL_REF_NUM,
  528.                                      CREATR_DEC_AIFF, FILTYP_DEC_AIFF);
  529.     else           set_mac_file_attr(decoded_file_name, VOL_REF_NUM,
  530.                                      CREATR_DEC_BNRY, FILTYP_DEC_BNRY);
  531. #endif
  532.  
  533.     printf("Decoding of \"%s\" is finished\n", encoded_file_name);
  534.     printf("The decoded PCM output file name is \"%s\"\n", decoded_file_name);
  535.     if (need_aiff)
  536.        printf("\"%s\" has been written with AIFF header information\n",
  537.               decoded_file_name);
  538.  
  539.     exit( 0 );
  540. }
  541.  
  542. static void usage()  /* print syntax & exit */
  543. {
  544.    fprintf(stderr,
  545.       "usage: %s                         queries for all arguments, or\n",
  546.        programName);
  547.    fprintf(stderr,
  548.       "       %s [-A][-s sb] inputBS [outPCM]\n", programName);
  549.    fprintf(stderr,"where\n");
  550.    fprintf(stderr," -A       write an AIFF output PCM sound file\n");
  551.    fprintf(stderr," -s sb    resynth only up to this sb (debugging only)\n");
  552.    fprintf(stderr," inputBS  input bit stream of encoded audio\n");
  553.    fprintf(stderr," outPCM   output PCM sound file (dflt inName+%s)\n",
  554.            DFLT_OPEXT);
  555.    exit(1);
  556. }
  557.